<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ctx</title>
    <link rel="stylesheet" href="../model/jsFn.css">
</head>
<body>
<div class="catalog">
    <h1>目录</h1>
    <ul>
        <li>
            <p><a href="#profile">ctx</a></p>
            <ul>
                <li><p><a href="#jsFn_Naive">Naive</a></p></li>
                <li><p><a href="#jsFn_invoker.interact">ctx.invoker.interact</a></p></li>
                <li><p><a href="#jsFn_forward">forward</a></p></li>
                <li><p><a href="#jsFn_getAgent">getAgent</a></p></li>
            </ul>
        </li>
    </ul>
</div>
<div id="profile">
    <h2>对象简介:</h2>
    <p>ctx:逻辑的上下文</p>
</div>
<!--对象的某一个方法-->
<div class="jsFnModel" id="jsFn_Naive">
    <h3>Naive:</h3>
    <div class="shape">
        <h3>函数使用样式</h3>
        <p>ctx.Naive() -> naive</p>
    </div>
    <div class="profile">
        <h3>函数功能简介</h3>
        <p>获得一个naive</p>
    </div>
    <div class="version" style="background: #c3c363">
        <p>稳定性;1 - 不稳定的</p>
        <p>新增于:v0.0.0</p>
    </div>
    <div class="params">
        <h3>参数列表:</h3>
        <p>无</p>
    </div>
    <div class="res">
        <h3>返回值:</h3>
        <p>naive</p>
        <p>分支控制器</p>
    </div>
    <div class="code">
        <h3>例子</h3>
        <pre>
            <code>
                context.naive.addLogic('login',async(ctx,pck)=>{
                    let naive = ctx.Naive();
                    let ws = await ctx.invoker.interact("wsconnect", 'socketHandler');//调用前端wsconnect动词
                    let agent = ctx.getAgent(`in_ws://${ws}`);//生成socket
                    naive.method("register",async(ctx,pck)=>{
                        console.log('注册分支');
                        let user = await ctx.forward("register");
                        return user;
                    });
                    naive.method("forget",async(ctx,pck)=>{
                        console.log('忘记密码');
                        ctx.forward("forget");
                    });
                    naive.method("login",async(ctx,pck)=>{
                        let {username,password} = pck;
                        console.log('输入账号,密码登录');
                        let user = {};
                        return user;
                    });
                    await ctx.invoker.interact('redirect',{url:"login.xml",naive});//跳转到登录页面
                    let hibernated = ctx.invoker.store();//在登录页面会执行不定时操作,让前端冻结等待回调;
                    let user = await naive.carry('register','login');//等待'register'或者'login'方法其中一个完成;
                    await hibernated(createAgent(agent));//不定时操作执行结束,前端解冻等待,接续执行逻辑;
                    return {naive}
                });
            </code>
        </pre>
    </div>
    <div class="error">
        <h3>抛出错误</h3>
    </div>
</div>
<div class="jsFnModel" id="jsFn_invoker.interact">
    <h3>ctx.invoker.interact:</h3>
    <div class="shape">
        <h3>函数使用样式</h3>
        <p>ctx.invoker.interact(verb,object) -> promise</p>
    </div>
    <div class="profile">
        <h3>函数功能简介</h3>
        <p>调用前端的verb动词库,若前端接收到调用并执行后,会返回res(true)</p>
    </div>
    <div class="version">
        <p>稳定性;2 - 稳定的</p>
        <p>新增于:v0.0.0</p>
    </div>
    <div class="params">
        <h3>参数列表:</h3>
        <ul>
            <li>
                <p>verb</p>
                <p>&nbsp;string&nbsp;</p>
                <p>前端存在的动词库</p>
            </li>
            <li>
                <p>object</p>
                <p>&nbsp;object&nbsp;</p>
                <p>调用对应动词时需要的参数</p>
            </li>
        </ul>
    </div>
    <div class="res">
        <h3>返回值:</h3>
        <p>promise</p>
        <p>res(message);前端接收到动词请求,执行相关函数后返回执行结果</p>
    </div>
    <div class="code">
        <h3>例子</h3>
        <pre>
            <code>
                context.naive.addLogic('test',async(ctx,pck)=>{
                    await ctx.invoker.interact('store',{name:'张三',id:1});//前端存下指定的键值对
                    let name = await ctx.invoker.interact('input',{url:'changeName.xml',id:1});
                    console.log(name);
                    let obj = await ctx.invoker.interact('retrieve',[name,id]);//获得前端已有的键值对
                    console.log(obj);
                    await ctx.invoker.interact('info','请耐心等待');//提示
                    await ctx.invoker.interact('wsconnect','afsfowhe');//调用socket
                    await ctx.invoker.interact('redirect',{url:'test.xml',id:12});//跳转页面,传给下一个页面{id:12}参数;
                    await ctx.invoker.interact('popup',{url:'test_dialog.xml',id:12});//弹出窗口,传给窗口{id:12}参数;
                });
            </code>
        </pre>
    </div>
    <div class="error">
        <h3>抛出错误</h3>
    </div>
</div>
<div class="jsFnModel" id="jsFn_forward">
    <h3>forward:</h3>
    <div class="shape">
        <h3>函数使用样式</h3>
        <p>ctx.forward(event,[data]) -> promise</p>
    </div>
    <div class="profile">
        <h3>函数功能简介</h3>
        <p>调用其他的逻辑入口,并得到返回值</p>
    </div>
    <div class="version">
        <p>稳定性;2 - 稳定的</p>
        <p>新增于:v0.0.0</p>
    </div>
    <div class="params">
        <h3>参数列表:</h3>
        <ul>
            <li>
                <p>event</p>
                <p>&nbsp;string&nbsp;</p>
                <p>逻辑入口名称</p>
            </li>
            <li>
                <p>data</p>
                <p>&nbsp;object&nbsp;</p>
                <p>指定的逻辑入口函数所需参数</p>
            </li>
        </ul>
    </div>
    <div class="res">
        <h3>返回值:</h3>
        <p>${返回值类型}</p>
        <p>${返回值代表含义}</p>
    </div>
    <div class="code">
        <h3>例子</h3>
        <pre>
            <code>
                context.naive.addLogic("forwardTest",async(ctx,pck)=>{
                    let {name} = pck;
                    console.log(name);
                    return true;
                });
                context.naive.addLogic("test",async(ctx,pck)=>{
                    let data = await = ctx.forward('forwardTest',{name:'张三'});
                    console.log(data);
                });
            </code>
        </pre>
    </div>
    <div class="error">
        <h3>抛出错误</h3>
    </div>
</div>
<div class="jsFnModel" id="jsFn_getAgent">
    <h3>getAgent:</h3>
    <div class="shape">
        <h3>函数使用样式</h3>
        <p>ctx.getAgent(wsconnect) -> agent</p>
    </div>
    <div class="profile">
        <h3>函数功能简介</h3>
        <p>建立socket连接</p>
    </div>
    <div class="version">
        <p>稳定性;2 - 稳定的</p>
        <p>新增于:v0.0.0</p>
    </div>
    <div class="params">
        <h3>参数列表:</h3>
        <ul>
            <li>
                <p>swconnect</p>
                <p>&nbsp;is_ws://+string&nbsp;</p>
                <p>建立socket连接</p>
            </li>
        </ul>
    </div>
    <div class="res">
        <h3>返回值:</h3>
        <p>agent</p>
        <p>建立的socket;可通过agent发起socket操作</p>
    </div>
    <div class="code">
        <h3>例子</h3>
        <pre>
            <code>
                    let ws = await ctx.invoker.interact("wsconnect", socketHandler);
                    let agent = ctx.getAgent(`in_ws://${ws}`);
                    agent.invoke("chat",{id:1,content:'你好'});
            </code>
        </pre>
    </div>
    <div class="error">
        <h3>抛出错误</h3>
    </div>
</div>
<div class="author"><p>by-草草</p></div>
</body>
</html>